package flyweight;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

class Bullet{
    UUID uid = UUID.randomUUID();
    boolean isLeaving = false;

    @Override
    public String toString() {
        return "Bullet{" +
                "uid=" + uid +
                ", isLeaving=" + isLeaving +
                '}';
    }
}

class BulletPool{
    List<Bullet> list = new ArrayList<>();
    private int flg = 0;

    BulletPool(int initLen){
        flg = initLen;
        kr(flg);
    }

    void kr(int initLen){
        for(int i=0; i<initLen;i++){
            list.add(new Bullet());
        }
    }

    Bullet getBullet(){
        for (Bullet item:list){
            if(item.isLeaving) return item;
        }

        kr(flg*2);

        Bullet bullet = new Bullet();
        list.add(bullet);

        System.out.println(list.size());

        return bullet;
    }
}

public class Flyweight {
    public static void main(String[] args) {
        System.out.println("Flyweight");

        BulletPool bulletPool = new BulletPool(100);

        System.out.println(bulletPool.getBullet());
    }
}
